using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantSubmarineSlowDownCollisionHandler
/// \brief  Handle submarine collision supposed to slow it down
[AddComponentMenu("GK/AbyssalGiant/Submarine/gkAbyssalGiantSubmarineSlowDownCollisionHandler")]
public class gkAbyssalGiantSubmarineSlowDownCollisionHandler : MonoBehaviour
{
	/// The boost reduce power multiply the velocity to a percentage
	public float BoostReductionPower = 0.0f;
	
	/// Boost acceleration
	public float BoostReductionAccelerationDuration = 0.25f;
	
	/// Boost duration
	public float BoostReductionDuration = 1.5f;
	
	/// Scrolling info
	private gkScrollingInfo m_rScrollingInfo;
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Grab the scrolling info
	    m_rScrollingInfo = GameObject.Find("ScrollingInfo").GetComponent<gkScrollingInfo>();
		
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{			
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkAbyssalGiantShockEvent.ShockBegin, HandleShockBeginEvent);
	}
	
	/// Handle the shock event
	void HandleShockBeginEvent(Object a_rEvent)
	{
		m_rScrollingInfo.Boost(BoostReductionPower, BoostReductionDuration, BoostReductionAccelerationDuration);
	}
}